package com.yuke.cloud.service.cmc.controller.frontend;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.cmc.entity.CmsAgreement;
import com.yuke.cloud.service.cmc.service.CmsAgreementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yukemall </br> </p>
 * <p>com.yuke.cloud.service.cmc.controller.frontend Description TODO </br> </p>
 * @Author wg
 * @Date   2019/4/11 10:15
 */
@Api(value = "WEB - MallCmsAgreementController", tags = "处理APP获取用户协议相关请求", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping("/mall/cms/agreement")
public class MallCmsAgreementController extends BaseController {
    @Resource
    private CmsAgreementService cmsAgreementService;

    @GetMapping
    @ApiOperation(httpMethod = "GET", value = "分页获取所有记录")
    public Wrapper<CmsAgreement> getAgreement(@ApiParam(name = "agreementType", value = "协议类型", defaultValue = "0") @RequestParam(defaultValue = "0") Integer agreementType
    ) {
        Example example = new Example(CmsAgreement.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("agreementType", agreementType);
        List<CmsAgreement> list = cmsAgreementService.selectByExample(example);

        CmsAgreement cmsAgreement = null;
        if (list != null && list.size() > 0) {
            cmsAgreement = list.get(0);
        }

        return WrapMapper.ok(cmsAgreement);
    }
}
